package com.net.wanjian.networkhospitalmanager.adapter;


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.net.wanjian.networkhospitalmanager.R;
import com.net.wanjian.networkhospitalmanager.adapter.base.RecyclerBaseAdapter;
import com.net.wanjian.networkhospitalmanager.bean.dopsminicex.GetScoreInformationBean;
import com.net.wanjian.networkhospitalmanager.utils.URLDecoderUtil;
import com.net.wanjian.networkhospitalmanager.view.LRatingBar;
import com.zhy.autolayout.utils.AutoUtils;

import java.text.DecimalFormat;
import java.util.HashMap;

/**
 * Created by WJ on 2017/8/24.
 */

public class InScoreInformationAdapter extends RecyclerBaseAdapter<GetScoreInformationBean.DataBean.EvaluationMarkSheetBean.EvaluationMarkSheetItemListBean, InScoreInformationAdapter.ViewHolderX> {
    private HashMap<Integer,Float> score;
    public InScoreInformationAdapter(Context context) {
        super(context);
        score = new HashMap<>();
    }

    @Override
    public ViewHolderX onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_dops_score_star, parent, false);
        AutoUtils.auto(view);
        return new ViewHolderX(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolderX holder, GetScoreInformationBean.DataBean.EvaluationMarkSheetBean.EvaluationMarkSheetItemListBean item, final int position) {
        holder.mItemTvDopsScoreTitle.setText(URLDecoderUtil.getDecoder(item.getMarkSheetItemContent()));
        LRatingBar ratingBar = holder.mItemDopsScoreStar;

        final TextView mItemTvDopsScore = holder.mItemTvDopsScore;
        ratingBar.setOnRatingChangeListener(new LRatingBar.OnRatingChangeListener() {
            @Override
            public void onRatingChange(float ratingCount) {
                Log.e("SSS", ratingCount+"" );
                switch ((int) ratingCount){
                    case 1:
                        mItemTvDopsScore.setText("非常不满意");
                        break;
                    case 2:
                        mItemTvDopsScore.setText("不满意");
                        break;
                    case 3:
                        mItemTvDopsScore.setText("一般");
                        break;
                    case 4:
                        mItemTvDopsScore.setText("勉强满意");
                        break;
                    case 5:
                        mItemTvDopsScore.setText("非常满意");
                        break;
                }
                score.put(position,  ratingCount);
            }
        });

    }

    class ViewHolderX extends RecyclerView.ViewHolder {
        LRatingBar mItemDopsScoreStar;
        TextView mItemTvDopsScoreTitle, mItemTvDopsScore;

        public ViewHolderX(View itemView) {
            super(itemView);
            mItemTvDopsScoreTitle = (TextView) itemView.findViewById(R.id.item_tv_dops_score_title);
            mItemDopsScoreStar = (LRatingBar) itemView.findViewById(R.id.item_dops_score_star);
            mItemTvDopsScore = (TextView) itemView.findViewById(R.id.item_tv_dops_score);
        }
    }
}
